package com.szcatic.ework.controller.other;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szcatic.ework.service.other.LoginTotalService;

import com.szcatic.ework.utils.PageInfoUtils;
import com.szcatic.ework.vo.other.LoginInfo;

/**
 * 用户登录统计Controller
 * @author Administrator
 *
 */
@RequestMapping("other/loginTotal")
@Controller
public class LoginTotalController {
	
	@Autowired
	private HttpServletRequest request;
	
	@Autowired
	private LoginTotalService loginTotalService;
	
	@RequestMapping("")
	@RequiresPermissions("other:loginTotal:select")
	public String index() {
		return "other/loginTotal";
	}
	
	@RequestMapping("queryList")
	@ResponseBody
	@RequiresPermissions("other:loginTotal:select")
	public Map<String,Object> queryOnlineList() {
		int page = 1,limit = 10;
		if (request.getParameter("page")!=null) {
			page = Integer.valueOf(request.getParameter("page"));
		}
		if (request.getParameter("limit") != null) {
			limit = Integer.valueOf(request.getParameter("limit"));
		}
		PageHelper.startPage(page, limit);
		List<LoginInfo> list = loginTotalService.onlineList();
		/*PageInfo<LoginInfo> pageInfo=new PageInfo<LoginInfo>(list);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("count", pageInfo.getTotal());
		map.put("data", pageInfo.getList());
		map.put("code", "0"); //成功的状态码
		map.put("msg", "");*/
		return PageInfoUtils.getPageInfo(list);
	}

}
